<template>
  <div class="fillcontain">
    <head-top></head-top>
    <div class="table_container">
        <el-row :gutter="20">
            <el-col :span="10" :offset="3" >
           <el-input placeholder="请输入内容" v-model="input3" class="input-with-select">
                <el-select style="width:130px" v-model="select" slot="prepend" placeholder="请选择">
                    <el-option v-for="item in selectOptions"
                    :key="item.value" 
                    :label="item.lable"
                     :value="item.value"></el-option>
                </el-select>
                <el-button @click="search" slot="append" icon="el-icon-search" >搜索</el-button>
            </el-input>
          </el-col>

        </el-row>
      <el-table :data="tableData" highlight-current-row style="width: 100%">
        <el-table-column type="id" property="reserveId" width="200" label="订单编号"> </el-table-column>
        <el-table-column property="sceneryName" label="景点名称" width="220">
        </el-table-column>
        <el-table-column property="tourName" label="预定人" width="100">
        </el-table-column>
          <el-table-column property="number" label="游玩人数" width="200">
        </el-table-column>
        <el-table-column property="money" label="总金额（元）" width="100">
        </el-table-column>
        <el-table-column property="state" label="订单状态"width="100"> </el-table-column>
        
        <el-table-column label="操作" width="200">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" @click="hexiao(scope.$index, scope.row)"
             :disabled="scope.row.status!=1" >核销</el-button
            >
             <el-button :disabled="scope.row.status!=1" type="danger" size="mini" @click="handleCancel(scope.$index, scope.row)"
              >取消</el-button
            >
            <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.$index, scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div class="Pagination" style="text-align: left; margin-top: 10px">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-size="10"
          layout="total, prev, pager, next"
          :total="count"
        >
        </el-pagination>
      </div>
   
    </div>
  </div>
</template>

<script>
import headTop from "../components/headTop";


import { getReserveList,cancelRserve,updateRserve } from "@/api/scenery";
export default {
  data() {
    return {
      tableData: [
        {
          nickName: "2016-05-02",
          phNum: "王小虎",
          province: "江西",
          city: "南昌",
          avatar:
            "https://thirdwx.qlogo.cn/mmopen/vi_32/VMWTEwwcHqfCD56TkJiaVcIoNm4QX1mxwhwts4kWBe6rrNsG75csjE1x4ibmSH1BNLG58gWj9RyQLhaunubapfZw/132",
          name: "",
          idNum: "",
        },
      ],
      list: [],
      currentRow: null,
      offset: 0,
      limit: 10,
      count: 0,
      currentPage: 1,
      dialogFormVisible:false,
      selectTable:{},
      input3:'',
      select:1,
      status:-1,
      selectOptions: [{
        lable:"ID",value:"1"
      },{
        lable:"用户名",value:"2"
      },{
        lable:"电话",value:"3"
      }]
    };
  },
  components: {
    headTop,
  },
  created() {
    this.initData(); 
    this.select = this.selectOptions[0].value
 
  },
  methods: {
    async initData() {
      try {
 

        this.getList();
      } catch (err) {
        console.log("获取数据失败", err);
      }
    },
    handleSizeChange(val) {
      this.limit = val;
      console.log(`每页 ${val} 条`);
      this.getList();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.offset = (val - 1) * this.limit;
      console.log(this.currentPage, this.offset);
      this.getList();
    },
    async getList() {
      console.log(this.currentPage,this.limit);
      const res = await getReserveList({ currentPage: this.currentPage, pageSize: this.limit,status:this.status });
      if(res&&res.code>=0){
        this.tableData  = res.data.rows;
        this.count = res.data.totalCount
      }else{
        console.log(res.message);
      }
      

    },

 
 //quxiao
    async handleCancel(index, row) {
 
      //index 就是第几个，可以从scenery直接取
      console.log("handleEdit(index, row)", index, row);
    let res= await cancelRserve(row.id)
    if(res.code>=0){
      this.$message.success('取消成功');this.getList();
    }else{
         this.$message.error(res.message);
    }   
    },
    async hexiao(index, row) {
      //index 就是第几个，可以从scenery直接取
      console.log("handleEdit(index, row)", index, row);
      let {id,status} = row
      console.log(id,status);
      //变为待评论
      status = 2
     let res=await  updateRserve({id,status})
    if(res.code>=0){
      this.$message.success("成功");
      this.getList()
    }else{
         this.$message.error(res.message);
    }   
    },
    async search(){
        console.log("input3",this.input3);
        console.log("select",this.select);
    },
    //跟新用户信息
    async  updateShop(){
        console.log(this.selectTable);
        let res= await updateUser(this.selectTable)
        if(res.code>=0){
             this.$message.success(res.message)
           
        }else
            this.$message.error(res.message);

         this.dialogUploadPicVisible=false;
    }
  },
};
</script>

<style lang="less">
@import "../style/mixin";
.table_container {
  padding: 20px;
}
</style>
